<html>
<head>
    <title>透析助手</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.5.6/css/sm.min.css">
    <link rel="stylesheet" href="__PUBLIC__/css/style.css">
    <link rel="stylesheet" href="__PUBLIC__/css/5s.css">
    <link rel="stylesheet" href="__PUBLIC__/css/6m.css">
    <link rel="stylesheet" href="__PUBLIC__/css/iconfont.css">
</head>
<body>
	<div class="head head-another">
		<div class="HeadContent">
			<a href="javascript:;" class="back"><i class="iconfont">&#xe605;</i></a>
			<a href="javascript:;" class="HeadTitle">添加用药</a>
		</div>
	</div>
	<div class="RecordInformation ChoseMedition">
		<ul>
            <input type="hidden" name="id" value="<{$vo.id}>" />
			<li onclick="javascript:$('.medicinePop').show();">
				<a href="javascript:;">
                    <div class="LeftTitle">药品名称</div>
                    <div class="RightContent">
                        <span id="med_name"><{$vo.name}></span>
                        <i class="iconfont">&#xe60a;</i>
                    </div>
                </a>
			</li>
            <li>
                <a href="javascript:;" ><div class="LeftTitle">药物剂量（<span id="vloWrap"><{:$medRow['sub_name']?$medRow['sub_name']:'量'}></span>）</div> </a>
                <div class="FoodDescribe">
                    <input type="tel" placeholder="请填写数值" id="med_vol" value="<{$vo.vol}>" />
                </div>
            </li>
			<li>
				<a href="javascript:;"><div class="LeftTitle">用药时间</div></a>
				<div class="WeekChose">
					<div class="<{:in_array('周一',$useTimeArr)?'active':''}>">
                        <span>周一</span>
                    </div>
					<div class="<{:in_array('周二',$useTimeArr)?'active':''}>">
                        <span>周二</span>
                    </div>
					<div class="<{:in_array('周三',$useTimeArr)?'active':''}>">
                        <span>周三</span>
                    </div>
                    <div class="<{:in_array('周四',$useTimeArr)?'active':''}>">
                        <span>周四</span>
                    </div>
                    <div class="<{:in_array('周五',$useTimeArr)?'active':''}>">
                        <span>周五</span>
                    </div>
                    <div class="<{:in_array('周六',$useTimeArr)?'active':''}>">
                        <span>周六</span>
                    </div>
                    <div class="<{:in_array('周日',$useTimeArr)?'active':''}>">
                        <span>周日</span>
                    </div>
				</div>
			</li>
			<li>
				<a href="javascript:;">
                    <textarea maxlength="150" id="des" placeholder="点击添加备注"><{$vo.des}></textarea>
                </a>
			</li>
		</ul>
	</div>

	<div class="BtnGroup NoFixed">
		<button onclick="del()">删除</button>
		<button class="btn-submit" onclick="save()">确定</button>
	</div>

    <!-- 药品名称弹框开始 -->
    <div class="Popwindow medicinePop">
        <div class="DinnerTime">
            <div class="DinnerTime-title">药品名称</div>
            <div class="DinnerTime-list">
                <ul>
                    <foreach name="medArr" item="v">
                        <li><a href="javascript:;">
                            <div class="LeftTitle"><{$v.name}></div>
                            <div class="RightContent">
                                <label class="form-radio timeLabel <{:$v['name']==$vo['name']?'active':''}>" data-id="<{$v.id}>" data-name="<{$v.name}>" data-subname="<{$v.sub_name}>">
                                    <i class="iconfont">&#xe610;</i>
                                </label>
                            </div>
                        </a></li>
                    </foreach>
                </ul>
            </div>
            <div class="BtnGroup Btn-Popwindow NoFixed">
                <button class="btn-drop" onclick="cancelTimeSection()">取消</button>
                <button class="btn-submit" onclick="saveTimeSection()">确定</button>
            </div>
        </div>
    </div>
    <!-- 药品名称弹框结束 -->
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.5.7/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='__PUBLIC__/js/myjq.js'></script>
<script>
    $(function() {
        //用药时间
        var w_weekchose = $(".WeekChose").width();
        //$(".WeekChose").height(w_weekchose * 0.12);
        //$(".WeekChose div").css("line-height", w_weekchose * 0.12 + "px");
        $(".WeekChose div").click(function() {
            if($(this).hasClass("active")){
                $(this).removeClass("active");
            }else{
                $(this).addClass("active");
            }
        });
    })
    
    //选中药名
    $('.timeLabel').click(function(){
        $('.timeLabel').removeClass('active');
        $(this).addClass('active');
    });
    //药名-确定
    function saveTimeSection(){
        $('#med_name').text($('.timeLabel.active').attr('data-name'));
        $('#vloWrap').text($('.timeLabel.active').attr('data-subname'));
        $('.medicinePop').hide();
    }
    //药名-取消
    function cancelTimeSection(){
        $('.medicinePop').hide();
    }
    
    //选中剂量
    function selVol(obj){
        $('.volLabel').removeClass('active');
        $(obj).addClass('active');
    }
    //剂量-确定
    function saveVol(){
        $('#med_vol').text($('.volLabel.active').attr('data-name'));
        $('.volPop').hide();
    }
    //剂量-取消
    function cancelVol(){
        $('.volPop').hide();
    }
    
    //保存
    function save(){
        if($('#med_name').text()==''){
            $.toast('请选择药品名');return;
        }
        if(!isNumber($('#med_vol').val())){
            $.toast('请填写正确的剂量值');return;
        }
        //用药时间
        var weekArr = [];
        for(var i=0;i<$('.WeekChose div').length;i++){
            if($('.WeekChose div').eq(i).hasClass('active')){
                weekArr.push($('.WeekChose div').eq(i).text()); 
            }
        }
        if(weekArr.length < 1){
            $.toast('请选择用药时间');return;
        }
        
        loadingShow();
        $.post("<{:U('edit')}>",{
            id:$("input[name='id']").val(),name:$('#med_name').text(),vol:$('#med_vol').val(),
            use_time:weekArr.join(','),des:$('#des').val()
        },function(res){
            if(res == 'suc'){
                toast('保存成功');
                setTimeout("location.href='<{:U('index')}>'",1200);
            }else{
                loadingHide();
                toast('保存失败');
            }
        });
    }
    
    //删除
    function del(){
        var id = "<{:I('get.id')}>";
        if(id == '') return;
        if(confirm('确定要删除吗？')){
            $.post("<{:U('del')}>",{id:id},function(res){
                if(res == 'suc'){
                    toast('删除成功');
                    setTimeout("location.href='<{:U('index')}>'",1200);
                }else{
                    toast('删除失败');
                }
            })
        }
    }
</script>
</body>
</html>